import MySQLdb


# get_connection
def get_connection():
    host = "127.0.0.1"
    username = "root"
    password = "123456"
    database = "upms-localhost";
    # get db connection
    db = MySQLdb.connect(host, username, password, database, charset='utf8');
    # get cursor
    cursor = db.cursor();
    # 使用execute方法执行SQL语句
    cursor.execute("SELECT VERSION()")
    # 使用 fetchone() 方法获取一条数据
    data = cursor.fetchone()
    print("Database version : %s " % data)
    # 关闭数据库连接
    db.close()
